
$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});

function save() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/member/circle/addCircle",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,

		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);
			} else {
				if (data.msg) {
					parent.layer.alert(data.msg)
				}else {
					window.location.href = "/";
				}
			}

		}
	});
}

function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			type_id : {
				required : true
			},
			username : {
				required : true
			},
			content : {
				required : true
			}
		},
		messages : {
			type_id : {
				required : icon + "圈子类型不能为空"
			},
			username : {
				required : icon + "用户不能为空"
			},
			content : {
				required : icon + "内容不能为空"
			}
		}
	})
}

/**
 * 加载图片URL
 * @param inputId
 * @param imgId
 * @param url
 */
function loadImgUrl(inputId, imgId, url) {
	$('#'+inputId +'').val(url);
	//$('#'+imgId +'').attr('src', url);
}

function onSelectImgBtnClick(inputId, imgId) {
	layer.open({
		id:'selectImg',
		type : 2,
		title : '选择图片',
		maxmin : true,
		shadeClose : false,
		area : [ '90%', '90%' ],
		content : '/platform/config/selectImg/' + inputId +"/"+ imgId // iframe的url
	});
}


function relateMember() {
	layer.open({
		id : "relation_member",
		type : 2,
		title : "选择会员",
		maxmin : true,
		shadeClose : true,
		area : [ '80%', '80%' ],
		content : "/mall/supply/relateMember?type=tjr"
	})
}

/**
 * 设置会员信息
 *
 * @param memberId
 * @param memberName
 */
function loadMemberInfo1(memberId, memberName) {
	$('#mermber_id').val(memberId)
	$('#username').val(memberName)
}

/**
 * 选择视频页面
 * @param inputId
 * @param imgId
 */
function onSelectVideoBtnClick(inputId, imgId) {
	layer.open({
		id:'selectImg',
		type : 2,
		title : '选择视频',
		maxmin : true,
		shadeClose : false,
		area : [ '90%', '90%' ],
		content : '/platform/config/selectVideo/' + inputId +"/"+ imgId // iframe的url
	});
}